﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using WEPMlibrary_Model;

namespace WEPMconnection_DAL
{
  public  class Member_DAL
    {
      Conntion Con = new Conntion();
      /// <summary>
      /// 查看团队
      /// </summary>
      /// <returns></returns>
      public List<Member> Team()
      {
          SqlConnection con =  Con.Con();
          con.Open();
          List<Member> list = new List<Member>();
          try
          {
              string sql = string.Format("SELECT	m.Id,mt.MemberTyep,ui.Name,p.ProjectName  FROM Member AS m INNER JOIN MemberTyeps AS mt ON m.Id=mt.Id INNER JOIN UserInfor AS ui ON m.Id=ui.Id INNER JOIN Project AS p ON m.Id=p.Id ");
              SqlCommand com = new SqlCommand(sql, con);
              SqlDataAdapter data = new SqlDataAdapter(com);
              DataTable table = new DataTable();
              data.Fill(table);
              foreach (DataRow item in table.Rows)
              {
                  Member mm = new Member();
                  mm.Id = Convert.ToInt32(item["Id"]);
                  mm.MemberTyep = item["MemberTyep"].ToString();
                  mm.ProjectName = item["ProjectName"].ToString();
                  mm.Name = item["Name"].ToString();
                  list.Add(mm);
              }
          }
          catch (Exception)
          {
              throw;
          }
          finally
          {
              con.Close();
          }
          return list;
      }
      /// <summary>
      /// 发送通知
      /// </summary>
      /// <param name="m"></param>
      /// <returns></returns>
      public int Message_Add(Message m)
      {
          int a;
          SqlConnection con = Con.Con();
          con.Open();
          try
          {
              string sql = string.Format("INSERT INTO MESSAGE(MessageContent,Uid)VALUES('{0}','{1}')",m.MessageContent,m.Uid);
              SqlCommand com = new SqlCommand(sql, con);
              a = com.ExecuteNonQuery();
          }
          catch (Exception)
          {
              throw;
          }
          finally
          {
              con.Close(); 
          }
          return a;
          
      }
    }
}
